Skip to content

fix: respect proxy when probing download URLs - #325

Open
Radiums wants to merge 2 commits into
MistEO:mainfrom
Radiums:fix/proxy-head-fallback
Open

fix: respect proxy when probing download URLs#325
Radiums wants to merge 2 commits into
MistEO:mainfrom
Radiums:fix/proxy-head-fallback

Conversation

@Radiums

@Radiums Radiums commented Aug 23, 2026

Copy link
Copy Markdown

Summary

  • route fallback download URL probes through a proxy-aware Tauri command
  • pass the configured update proxy to the GitHub HEAD probe
  • reuse the existing reqwest proxy setup and add a regression test with a local proxy server

Problem

The GitHub Release API request respects the app's update proxy, but its fallback path probes constructed release URLs with tauriFetch. That HEAD request does not receive the app-configured proxy, so users who rely on the update proxy can fail before the actual package download starts.

Testing

  • TypeScript compilation (tsc)
  • Vite production build
  • Prettier check for the changed TypeScript file
  • Rust formatting check for the changed command
  • Added probe_download_url_uses_explicit_proxy regression test

The Rust test could not be linked locally because MSVC link.exe is unavailable on this machine; the application code will be compiled by the repository's Windows CI.

Sourcery 摘要

通过配置的代理路由备用下载 URL 探测,以支持在使用代理的环境中进行更新。

新功能:

  • 添加支持代理的命令,用于探测直接下载 URL。

错误修复:

  • 确保备用下载 URL 探测遵循配置的更新代理。

增强功能:

  • 复用共享代理配置来处理 GitHub 发布请求和直接下载检查。

测试:

  • 添加回归测试,验证直接 URL 探测会通过显式代理进行路由。
Original summary in English

Sourcery 总结

通过配置的更新代理路由备用下载 URL 探测请求。

新功能:

  • 添加支持代理的命令,用于探测直接下载 URL。

错误修复:

  • 确保备用下载 URL 检查遵循配置的更新代理。

增强功能:

  • GitHub release 请求和直接下载探测复用共享的代理配置。

测试:

  • 添加回归测试,验证直接 URL 探测请求会通过显式代理进行路由。
Original summary in English

Summary by Sourcery

Route fallback download URL probes through the configured update proxy.

New Features:

  • Add a proxy-aware command for probing direct download URLs.

Bug Fixes:

  • Ensure fallback download URL checks honor the configured update proxy.

Enhancements:

  • Reuse shared proxy configuration for GitHub release requests and direct download probes.

Tests:

  • Add a regression test verifying that direct URL probes are routed through an explicit proxy.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嘿——我发现了 1 个问题

面向 AI Agent 的提示
请处理本次代码审查中的评论:

## 个别评论

### 评论 1
<location path="src-tauri/src/commands/download.rs" line_range="629-632" />
<code_context>
+        let proxy_address = listener.local_addr().expect("get test proxy address");
+        let proxy = std::thread::spawn(move || {
+            let (mut stream, _) = listener.accept().expect("accept proxied request");
+            let mut request = [0_u8; 2048];
+            let bytes_read = stream.read(&mut request).expect("read proxied request");
+            let request = String::from_utf8_lossy(&request[..bytes_read]);
+            assert!(request.starts_with("HEAD http://example.invalid/update.zip HTTP/1.1"));
+            stream
+                .write_all(
</code_context>
<issue_to_address>
**问题(测试):** 回归测试假设一次 `read` 调用会返回完整的 HTTP 请求,并针对该部分缓冲区进行断言。TCP 读取没有消息边界,因此当一个有效的代理请求被拆分到多个数据包中时,该断言会间歇性失败。

**触发条件:** 代理请求的请求头分散在多个 TCP 段中到达时。

**建议修复:** 在断言请求行之前循环读取,直到收到 `\r\n\r\n` 请求头结束符。

```suggestion
            let mut request = Vec::new();
            loop {
                let mut chunk = [0_u8; 2048];
                let bytes_read = stream.read(&mut chunk).expect("read proxied request");
                assert!(bytes_read > 0, "proxy closed before request headers");
                request.extend_from_slice(&chunk[..bytes_read]);
                if request.windows(4).any(|window| window == b"\r\n\r\n") {
                    break;
                }
            }
            let request = String::from_utf8_lossy(&request);
            assert!(request.starts_with("HEAD http://example.invalid/update.zip HTTP/1.1"));
```
</issue_to_address>

Sourcery 对开源项目免费——如果你喜欢我们的审查,请考虑分享它们 ✨
帮助我变得更有用!请在每条评论上点击 👍 或 👎,我会利用这些反馈来改进审查。
Original comment in English

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src-tauri/src/commands/download.rs" line_range="629-632" />
<code_context>
+        let proxy_address = listener.local_addr().expect("get test proxy address");
+        let proxy = std::thread::spawn(move || {
+            let (mut stream, _) = listener.accept().expect("accept proxied request");
+            let mut request = [0_u8; 2048];
+            let bytes_read = stream.read(&mut request).expect("read proxied request");
+            let request = String::from_utf8_lossy(&request[..bytes_read]);
+            assert!(request.starts_with("HEAD http://example.invalid/update.zip HTTP/1.1"));
+            stream
+                .write_all(
</code_context>
<issue_to_address>
**issue (testing):** The regression test assumes one `read` call returns the complete HTTP request and asserts against that partial buffer. TCP reads are not message-framed, so a valid proxied request split across packets causes the assertion to fail intermittently.

**Triggers:** When the proxy request headers arrive in multiple TCP segments.

**Suggested fix:** Read in a loop until the `\r\n\r\n` header terminator is received before asserting the request line.

```suggestion
            let mut request = Vec::new();
            loop {
                let mut chunk = [0_u8; 2048];
                let bytes_read = stream.read(&mut chunk).expect("read proxied request");
                assert!(bytes_read > 0, "proxy closed before request headers");
                request.extend_from_slice(&chunk[..bytes_read]);
                if request.windows(4).any(|window| window == b"\r\n\r\n") {
                    break;
                }
            }
            let request = String::from_utf8_lossy(&request);
            assert!(request.starts_with("HEAD http://example.invalid/update.zip HTTP/1.1"));
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src-tauri/src/commands/download.rs Outdated
@MistEO

MistEO commented Aug 26, 2026

Copy link
Copy Markdown
Owner

没看懂,这干嘛的,现在 github 不是有代理吗?

@Radiums

Radiums commented Aug 26, 2026

Copy link
Copy Markdown
Author

没看懂,这干嘛的,现在 github 不是有代理吗?

fallback的时候没走代理

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants